/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.EditorMenu;

import GUI.Dialogs.ScreenshotDialog;
import General.CurrentData;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.*;

/**
 *
 * @author David
 */
public class ExtrasMenu extends JMenu
{

    private JMenu autosaveMenu = new JMenu("Autosave");
    private JCheckBoxMenuItem autosaveEnabledItem = new JCheckBoxMenuItem("Enabled");
    private JMenuItem autosaveOptionsItem = new JMenuItem("Options");
    private JMenuItem screenshotItem = new JMenuItem("Screenshot");
    private JMenuItem recordItem = new JMenuItem("Record");
    private JMenuItem randomItem = new JMenuItem("Randomnes");

    /**
     *
     */
    public ExtrasMenu()
    {
        initShortcuts();
        setEnabled(false);
        setText("Extras");
        add(autosaveMenu);
        autosaveMenu.add(autosaveEnabledItem);
        autosaveMenu.add(autosaveOptionsItem);
        add(screenshotItem);
        add(recordItem);
        add(new JSeparator());
        add(randomItem);
        initActions();
    }

    private void initActions()
    {
        screenshotItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                new ScreenshotDialog();
            }
        });
        randomItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                try
                {
                    java.awt.Desktop.getDesktop().browse(new URI("http://www.9gag.com/random"));
                } catch (IOException ex)
                {
                    CurrentData.getObserverDialog().printError("IO Error calling 9gag", ex);
                } catch (URISyntaxException ex)
                {
                    CurrentData.getObserverDialog().printError("URI Syntax-Error calling 9gag", ex);
                }
            }
        });
    }

    private void initShortcuts()
    {
        screenshotItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0));
        recordItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0));
        randomItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0));
    }
}
